<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  
  
  <title>manim基础整理 | Hexo</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  <meta name="description" content="manimInstallationManim runs on Python 3.6 or higher (Python 3.8 is recommended).System requirements are FFmpeg OpenGL (included in python package PyOpenGL) LaTeX (optional, if you want to use LaTeX) P">
<meta property="og:type" content="article">
<meta property="og:title" content="manim基础整理">
<meta property="og:url" content="https://goofyer.gitee.io/notes-on-computer-expertise/2022/01/02/python/manim/manim%E5%9F%BA%E7%A1%80%E6%95%B4%E7%90%86/index.html">
<meta property="og:site_name" content="Hexo">
<meta property="og:description" content="manimInstallationManim runs on Python 3.6 or higher (Python 3.8 is recommended).System requirements are FFmpeg OpenGL (included in python package PyOpenGL) LaTeX (optional, if you want to use LaTeX) P">
<meta property="og:locale" content="en_US">
<meta property="article:published_time" content="2022-01-02T06:56:00.000Z">
<meta property="article:modified_time" content="2022-03-27T08:02:50.431Z">
<meta property="article:author" content="John Doe">
<meta name="twitter:card" content="summary">
  
    <link rel="alternate" href="/notes-on-computer-expertise/atom.xml" title="Hexo" type="application/atom+xml">
  
  
    <link rel="shortcut icon" href="/notes-on-computer-expertise/favicon.png">
  
  
    
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/typeface-source-code-pro@0.0.71/index.min.css">

  
  
<link rel="stylesheet" href="/notes-on-computer-expertise/css/style.css">

  
    
<link rel="stylesheet" href="/notes-on-computer-expertise/fancybox/jquery.fancybox.min.css">

  
<meta name="generator" content="Hexo 5.4.0"></head>

<body>
  <div id="container">
    <div id="wrap">
      <header id="header">
  <div id="banner"></div>
  <div id="header-outer" class="outer">
    <div id="header-title" class="inner">
      <h1 id="logo-wrap">
        <a href="/notes-on-computer-expertise/" id="logo">Hexo</a>
      </h1>
      
    </div>
    <div id="header-inner" class="inner">
      <nav id="main-nav">
        <a id="main-nav-toggle" class="nav-icon"></a>
        
          <a class="main-nav-link" href="/notes-on-computer-expertise/">Home</a>
        
          <a class="main-nav-link" href="/notes-on-computer-expertise/archives">Archives</a>
        
      </nav>
      <nav id="sub-nav">
        
          <a id="nav-rss-link" class="nav-icon" href="/notes-on-computer-expertise/atom.xml" title="RSS Feed"></a>
        
        <a id="nav-search-btn" class="nav-icon" title="Search"></a>
      </nav>
      <div id="search-form-wrap">
        <form action="//google.com/search" method="get" accept-charset="UTF-8" class="search-form"><input type="search" name="q" class="search-form-input" placeholder="Search"><button type="submit" class="search-form-submit">&#xF002;</button><input type="hidden" name="sitesearch" value="https://goofyer.gitee.io/notes-on-computer-expertise"></form>
      </div>
    </div>
  </div>
</header>

      <div class="outer">
        <section id="main"><article id="post-python/manim/manim基础整理" class="h-entry article article-type-post" itemprop="blogPost" itemscope itemtype="https://schema.org/BlogPosting">
  <div class="article-meta">
    <a href="/notes-on-computer-expertise/2022/01/02/python/manim/manim%E5%9F%BA%E7%A1%80%E6%95%B4%E7%90%86/" class="article-date">
  <time class="dt-published" datetime="2022-01-02T06:56:00.000Z" itemprop="datePublished">2022-01-02</time>
</a>
    
  <div class="article-category">
    <a class="article-category-link" href="/notes-on-computer-expertise/categories/manim/">manim</a>
  </div>

  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 class="p-name article-title" itemprop="headline name">
      manim基础整理
    </h1>
  

      </header>
    
    <div class="e-content article-entry" itemprop="articleBody">
      
        <h1 id="manim"><a href="#manim" class="headerlink" title="manim"></a>manim</h1><h2 id="Installation"><a href="#Installation" class="headerlink" title="Installation"></a>Installation</h2><h3 id="Manim-runs-on-Python-3-6-or-higher-Python-3-8-is-recommended"><a href="#Manim-runs-on-Python-3-6-or-higher-Python-3-8-is-recommended" class="headerlink" title="Manim runs on Python 3.6 or higher (Python 3.8 is recommended)."></a>Manim runs on Python 3.6 or higher (Python 3.8 is recommended).</h3><h3 id="System-requirements-are"><a href="#System-requirements-are" class="headerlink" title="System requirements are"></a>System requirements are</h3><ul>
<li>FFmpeg</li>
<li>OpenGL (included in python package PyOpenGL)</li>
<li>LaTeX (optional, if you want to use LaTeX)</li>
<li>Pango (only for Linux)<h3 id="Directly"><a href="#Directly" class="headerlink" title="Directly"></a>Directly</h3></li>
<li>Install manimgl<ul>
<li>pip install manimgl</li>
</ul>
</li>
<li>Try it out<ul>
<li>manimgl</li>
</ul>
</li>
<li>If you want to hack on manimlib itself, clone this repository and in that directory execute:<ul>
<li>Install python requirements<ul>
<li>pip install -e .</li>
</ul>
</li>
<li>Try it out<ul>
<li>manimgl example_scenes.py OpeningManimExample# or</li>
<li>manim-render example_scenes.py OpeningManimExample</li>
</ul>
</li>
</ul>
</li>
<li>1.Install FFmpeg, and make sure that its path is in the PATH environment variable.</li>
<li>2.Install a LaTeX distribution. TeXLive-full is recommended.</li>
<li>3.Install the remaining Python packages.</li>
<li>git clone <a target="_blank" rel="noopener" href="https://github.com/3b1b/manim.gitcd">https://github.com/3b1b/manim.gitcd</a> manim</li>
<li>pip install -e .</li>
<li>manimgl example_scenes.py OpeningManimExample<h3 id="For-Anaconda"><a href="#For-Anaconda" class="headerlink" title="For Anaconda"></a>For Anaconda</h3></li>
<li>Install FFmpeg and LaTeX as above.</li>
<li>Create a conda environment using</li>
<li>git clone <a target="_blank" rel="noopener" href="https://github.com/3b1b/manim.gitcd">https://github.com/3b1b/manim.gitcd</a> manim</li>
<li>conda create -n manim python=3.8</li>
<li>conda activate manim</li>
<li>pip install -e .</li>
</ul>
<h2 id="python-贪吃蛇"><a href="#python-贪吃蛇" class="headerlink" title="python 贪吃蛇"></a>python 贪吃蛇</h2><h3 id="main主函数"><a href="#main主函数" class="headerlink" title="main主函数"></a>main主函数</h3><ul>
<li>相关初始化工作<ul>
<li>显示welcome</li>
<li>游戏结束了，显示game over</li>
</ul>
</li>
<li>游戏主题运行<ul>
<li>蛇身位置、食物位置初始化</li>
<li>监听键盘</li>
<li>判断蛇的状态，死亡</li>
<li>更新画面</li>
</ul>
</li>
<li>Screen=Square(color=YELLOW,fill_color=YELLOW,fill_opacity=0.2,width=8,height=8)</li>
<li>title=TextMobject(“python 贪吃蛇”)</li>
<li>title.to_edge(UP)</li>
<li>self.play(FadeIN(Screen),Write(title))</li>
<li>show_start_info(screen)               #欢迎信息</li>
<li>self.wait(3)</li>
<li>running_game(snake_speed=2)</li>
<li>show_gameover_info()<h3 id="代码框架"><a href="#代码框架" class="headerlink" title="代码框架"></a>代码框架</h3></li>
<li>def running_game(self,snake_speed):</li>
<li>开始后，进入游戏内循环，直到游戏结束</li>
<li>对于贪吃蛇，采用元组保存，根据元组打印出贪吃蛇</li>
<li>def draw_food(self,food):</li>
<li>def draw_snake(self,snake_coords):</li>
<li>def move_snake(self,snake_coords):</li>
<li>移动做法具体是，我们把每次头部移动的新坐标插入贪吃蛇元组，然后删掉尾部一节</li>
<li>def snake_is_alive(self,snake_coords):</li>
<li>def snake_is_eat(self,snake_coords,food):</li>
<li>def get_random_location(self):</li>
<li>def get_start_info(self):</li>
<li>def show_gameover_info(self):</li>
<li>def draw_score(self,score):</li>
<li>def terminate(self):<h3 id="ai"><a href="#ai" class="headerlink" title="ai"></a>ai</h3></li>
<li>这两天在网上看到一张让人涨姿势的图片，图片中展示的是贪吃蛇游戏， 估计大部分人都玩过。但如果仅仅是贪吃蛇游戏，那么它就没有什么让人涨姿势的地方了。 问题的关键在于，图片中的贪吃蛇真的很贪吃XD，它把矩形中出现的食物吃了个遍， 然后华丽丽地把整个矩形填满，真心是看得赏心悦目。作为一个CSer， 第一个想到的是，这东西是写程序实现的(因为，一般人干不出这事。 果断是要让程序来干的)第二个想到的是，写程序该如何实现，该用什么算法？ 既然开始想了，就开始做。因为Talk is cheap，要show me the code才行。 (从耗子叔那学来的)</li>
<li><p>最初的问题</p>
<ul>
<li>在一个矩形中，每一时刻有一个食物，贪吃蛇要在不撞到自己的条件下，<br>找到一条路(未必要最优)，然后沿着这条路运行，去享用它的美食</li>
</ul>
</li>
<li><p>简单版本</p>
<ul>
<li>我们先不去想蛇会越来越长这个事实，问题基本就是，给你一个起点(蛇头)和一个终点( 食物)，要</li>
<li>BFS</li>
<li>DFS</li>
<li>A*</li>
</ul>
</li>
<li><p>1.1版本</p>
<ul>
<li>但是当蛇身变长，很容易就遇到看不到食物困境，我们可以选择的方法有：<ul>
<li>让蛇随便走走</li>
</ul>
</li>
</ul>
</li>
<li>2.0版本<ul>
<li>思考以下这些问题<ul>
<li>蛇和食物间有路径直接就去吃，不可取。那该怎么办？</li>
<li>如果蛇去吃食物后，布局是安全的，是否就直接去吃？(这样最优吗？)</li>
<li>怎样定义布局是否安全？<ul>
<li>跟着蛇尾走。只要蛇和食物间不存在路径， 蛇就一直跟着蛇尾走</li>
</ul>
</li>
<li>蛇和食物之间如果没有路径，怎么办？</li>
<li>最短路径是否最优？(这个明显不是了)</li>
<li>那么，如果布局安全的情况下，最短路径是否最优？</li>
<li>除了最短路径，我们还可以怎么走？S形？最长？</li>
<li>怎么应对蛇身越来越长这个问题？</li>
<li>食物是随机出现的，有没可能出现无解的布局？</li>
<li>暴力法(brute force)能否得到最优序列？(让贪吃蛇尽可能地多吃食物)</li>
</ul>
</li>
<li>策略1：判断食物与尾巴之间是否存在路径<ul>
<li>不存在尾巴到达食物的路径<ul>
<li>自己看不见尾巴<ul>
<li>随机撞墙</li>
</ul>
</li>
<li>可以看见尾巴<ul>
<li>追尾</li>
</ul>
</li>
</ul>
</li>
<li>存在尾巴到达食物的路径（安全）<ul>
<li>看不见食物<ul>
<li>看不见尾巴<ul>
<li>随机</li>
</ul>
</li>
<li>看见尾巴<ul>
<li>追尾</li>
</ul>
</li>
</ul>
</li>
<li>看见食物<ul>
<li>吃食物</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
<li>策略2：<ul>
<li>如果存在尾巴到达食物的安全路径，且可以看到食物<ul>
<li>吃食物</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>

      
    </div>
    <footer class="article-footer">
      <a data-url="https://goofyer.gitee.io/notes-on-computer-expertise/2022/01/02/python/manim/manim%E5%9F%BA%E7%A1%80%E6%95%B4%E7%90%86/" data-id="cl403sxsn004wf8vu849jhmlx" data-title="manim基础整理" class="article-share-link">Share</a>
      
      
      
    </footer>
  </div>
  
    
<nav id="article-nav">
  
    <a href="/notes-on-computer-expertise/2022/01/02/%E8%AE%A1%E7%AE%97%E6%9C%BA%E7%BD%91%E7%BB%9C/%E8%AE%A1%E7%AE%97%E6%9C%BA%E7%BD%91%E7%BB%9C%E5%9F%BA%E7%A1%80%E7%9F%A5%E8%AF%86/" id="article-nav-newer" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Newer</strong>
      <div class="article-nav-title">
        
          计算机网络基础知识
        
      </div>
    </a>
  
  
    <a href="/notes-on-computer-expertise/2022/01/02/%E8%99%9A%E5%B9%BB4%E5%BC%95%E6%93%8E%E5%BC%80%E5%8F%91/%E7%AC%AC%E4%B8%80%E8%AF%BE-%E4%BB%80%E4%B9%88%E6%98%AF%E8%99%9A%E5%B9%BB4/" id="article-nav-older" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Older</strong>
      <div class="article-nav-title">第一课 什么是虚幻4</div>
    </a>
  
</nav>

  
</article>


</section>
        
          <aside id="sidebar">
  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Categories</h3>
    <div class="widget">
      <ul class="category-list"><li class="category-list-item"><a class="category-list-link" href="/notes-on-computer-expertise/categories/C-%E5%B7%A5%E5%85%B7/">C#工具</a></li><li class="category-list-item"><a class="category-list-link" href="/notes-on-computer-expertise/categories/C-%E5%B7%A5%E5%85%B7/">C++工具</a></li><li class="category-list-item"><a class="category-list-link" href="/notes-on-computer-expertise/categories/Mysql/">Mysql</a></li><li class="category-list-item"><a class="category-list-link" href="/notes-on-computer-expertise/categories/blender/">blender</a></li><li class="category-list-item"><a class="category-list-link" href="/notes-on-computer-expertise/categories/linux/">linux</a></li><li class="category-list-item"><a class="category-list-link" href="/notes-on-computer-expertise/categories/manim/">manim</a></li><li class="category-list-item"><a class="category-list-link" href="/notes-on-computer-expertise/categories/spring/">spring</a></li><li class="category-list-item"><a class="category-list-link" href="/notes-on-computer-expertise/categories/vba%E5%9F%BA%E7%A1%80%E6%93%8D%E4%BD%9C/">vba基础操作</a></li><li class="category-list-item"><a class="category-list-link" href="/notes-on-computer-expertise/categories/%E5%88%9B%E9%80%A0%E6%A8%A1%E5%BC%8F/">创造模式</a></li><li class="category-list-item"><a class="category-list-link" href="/notes-on-computer-expertise/categories/%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F/">操作系统</a></li><li class="category-list-item"><a class="category-list-link" href="/notes-on-computer-expertise/categories/%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F%E5%9F%BA%E7%A1%80%E7%9F%A5%E8%AF%86/">操作系统基础知识</a></li><li class="category-list-item"><a class="category-list-link" href="/notes-on-computer-expertise/categories/%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F%E5%BC%80%E5%8F%91/">操作系统开发</a></li><li class="category-list-item"><a class="category-list-link" href="/notes-on-computer-expertise/categories/%E6%95%B0%E5%AD%A6/">数学</a></li><li class="category-list-item"><a class="category-list-link" href="/notes-on-computer-expertise/categories/%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84/">数据结构</a></li><li class="category-list-item"><a class="category-list-link" href="/notes-on-computer-expertise/categories/%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84%E5%9F%BA%E7%A1%80%E7%9F%A5%E8%AF%86/">数据结构基础知识</a></li><li class="category-list-item"><a class="category-list-link" href="/notes-on-computer-expertise/categories/%E6%A8%A1%E6%9D%BF/">模板</a></li><li class="category-list-item"><a class="category-list-link" href="/notes-on-computer-expertise/categories/%E6%B7%B1%E5%BA%A6%E5%AD%A6%E4%B9%A0/">深度学习</a></li><li class="category-list-item"><a class="category-list-link" href="/notes-on-computer-expertise/categories/%E8%8B%B1%E8%AF%AD/">英语</a></li><li class="category-list-item"><a class="category-list-link" href="/notes-on-computer-expertise/categories/%E8%99%9A%E5%B9%BB4/">虚幻4</a></li><li class="category-list-item"><a class="category-list-link" href="/notes-on-computer-expertise/categories/%E8%AE%A1%E7%AE%97%E6%9C%BA%E7%BB%84%E6%88%90%E5%8E%9F%E7%90%86/">计算机组成原理</a></li><li class="category-list-item"><a class="category-list-link" href="/notes-on-computer-expertise/categories/%E8%AE%A1%E7%AE%97%E6%9C%BA%E7%BD%91%E7%BB%9C/">计算机网络</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Tags</h3>
    <div class="widget">
      <ul class="tag-list" itemprop="keywords"><li class="tag-list-item"><a class="tag-list-link" href="/notes-on-computer-expertise/tags/C/" rel="tag">C++</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Tag Cloud</h3>
    <div class="widget tagcloud">
      <a href="/notes-on-computer-expertise/tags/C/" style="font-size: 10px;">C++</a>
    </div>
  </div>

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Archives</h3>
    <div class="widget">
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/notes-on-computer-expertise/archives/2022/05/">May 2022</a></li><li class="archive-list-item"><a class="archive-list-link" href="/notes-on-computer-expertise/archives/2022/03/">March 2022</a></li><li class="archive-list-item"><a class="archive-list-link" href="/notes-on-computer-expertise/archives/2022/02/">February 2022</a></li><li class="archive-list-item"><a class="archive-list-link" href="/notes-on-computer-expertise/archives/2022/01/">January 2022</a></li><li class="archive-list-item"><a class="archive-list-link" href="/notes-on-computer-expertise/archives/2021/12/">December 2021</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Recent Posts</h3>
    <div class="widget">
      <ul>
        
          <li>
            <a href="/notes-on-computer-expertise/2022/05/31/vue/%E5%89%8D%E7%AB%AF%E6%A1%86%E6%9E%B6%E9%AA%8C%E8%AF%81%E7%A0%81%E6%97%A0%E6%B3%95%E6%98%BE%E7%A4%BA/">(no title)</a>
          </li>
        
          <li>
            <a href="/notes-on-computer-expertise/2022/05/26/%E6%95%B0%E6%8D%AE%E5%BA%93/navicat%E5%AE%89%E8%A3%85/">(no title)</a>
          </li>
        
          <li>
            <a href="/notes-on-computer-expertise/2022/05/25/%E8%99%9A%E5%B9%BB4%E5%BC%95%E6%93%8E%E5%BC%80%E5%8F%91/%E8%99%9A%E5%B9%BB%E5%9B%9B%20mod%E5%88%B6%E4%BD%9C/">(no title)</a>
          </li>
        
          <li>
            <a href="/notes-on-computer-expertise/2022/05/23/python/python%E6%89%B9%E9%87%8F%E7%94%9F%E6%88%90%E6%95%B0%E6%8D%AE/">(no title)</a>
          </li>
        
          <li>
            <a href="/notes-on-computer-expertise/2022/05/23/vba%E5%9F%BA%E7%A1%80%E6%93%8D%E4%BD%9C%E7%AC%94%E8%AE%B0/EXCEL%E5%9F%BA%E7%A1%80%E6%95%99%E7%A8%8B/">(no title)</a>
          </li>
        
      </ul>
    </div>
  </div>

  
</aside>
        
      </div>
      <footer id="footer">
  
  <div class="outer">
    <div id="footer-info" class="inner">
      
      &copy; 2022 John Doe<br>
      Powered by <a href="https://hexo.io/" target="_blank">Hexo</a>
    </div>
  </div>
</footer>

    </div>
    <nav id="mobile-nav">
  
    <a href="/notes-on-computer-expertise/" class="mobile-nav-link">Home</a>
  
    <a href="/notes-on-computer-expertise/archives" class="mobile-nav-link">Archives</a>
  
</nav>
    


<script src="/notes-on-computer-expertise/js/jquery-3.4.1.min.js"></script>



  
<script src="/notes-on-computer-expertise/fancybox/jquery.fancybox.min.js"></script>




<script src="/notes-on-computer-expertise/js/script.js"></script>





  </div>
<script type="text/x-mathjax-config">
    MathJax.Hub.Config({
        tex2jax: {
            inlineMath: [ ["$","$"], ["\\(","\\)"] ],
            skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code'],
            processEscapes: true
        }
    });
    MathJax.Hub.Queue(function() {
        var all = MathJax.Hub.getAllJax();
        for (var i = 0; i < all.length; ++i)
            all[i].SourceElement().parentNode.className += ' has-jax';
    });
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-MML-AM_CHTML"></script>
</body>
</html>